package com.useeinfo.asg.open.web;

import com.useeinfo.asg.common.utils.CommUtil;
import com.useeinfo.asg.modules.logging.biz.ArticleBiz;
import com.useeinfo.asg.modules.logging.biz.CommentBiz;
import com.useeinfo.asg.modules.logging.entity.Article;
import com.useeinfo.asg.modules.logging.entity.Comment;
import com.useeinfo.framework.sugar.data.QueryParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 */
@Controller
@RequestMapping("/mobile/article")
public class ArticleManageAction {

    @Autowired
    private ArticleBiz articleBiz;
    @Autowired
    private CommentBiz commentBiz;

    @RequestMapping("/listJson")
    public String listJosn(@RequestParam(value = "page", required = false) String pageNowParam,
                               @RequestParam(value = "rows", required = false) String pageSizeParam,
                               @RequestParam(value = "name", required = false) String sidxParam,
                           ModelMap mv) {

        QueryParam queryParam = new QueryParam(-1, -1);

        List<Article>articleList = articleBiz.findList(queryParam);
        mv.put("articleList",articleList);
        return "mobile/articlelist";
    }

    /**
     * 文章详情
     *
     * @param request
     * @param mv
     * @return
     */
    @RequestMapping("/detail")
    public String detail(HttpServletRequest request, ModelMap mv) {

        String id = request.getParameter("id");
        Article article = articleBiz.findModel(CommUtil.null2Long(id));
        QueryParam queryParam = new QueryParam(-1, -1);
        queryParam.getSqlMap().put("articleID", id);
        List<Comment> commentList = commentBiz.findList(queryParam);
        mv.put("commentList", commentList);
        mv.put("article", article);
        return "mobile/article";
    }
}
